package bootstrap

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/dig"
	"owl"
	"owl/web_server"
	"resume/app/controller/music"
)

var Stage *owl.Stage

var providers = []owl.Dependency{
	{
		Construct: func(stage *owl.Stage, e *gin.Engine) *web_server.HttpService {
			return web_server.NewHttpService(stage, e, nil)
		},
	},
	{
		Construct: music.NewMusicController,
	},
}

func init() {

	Stage = owl.New()
	_ = Stage.Provide(func() *owl.Stage {
		return Stage
	})

	for _, provider := range providers {
		if provider.Interface != nil {
			err := Stage.Provide(provider.Construct, dig.As(provider.Interface))
			if err != nil {
				panic(err)
			}
		} else {
			err := Stage.Provide(provider.Construct)
			if err != nil {
				panic(err)
			}
		}
	}
}
